﻿#include "head.h"
//添加景点
int addspot_back(char* name, char* info, Node node[], int idx) {//ܺ
	strcpy(node[idx].name, name);
	strcpy(node[idx].info, info);
	return 1;
}

void addspot(Node node[]) {
	char spotname[MAXSPOTNAME];
	char spotinfo[MAXSPOTINFO];
	while (1) {
		system("cls");
		//获取景点数量，进行是否达到数量上限
		int nodecount = getnodecount(node);
		if (nodecount + 1 == MaxSize) {
			cout << "无法添加！已达添加上限" << endl;
			system("pause");
			return;
		}
		printspot(node);
		cout << "请输入新景点名称(输入“0”退出)：";
		cin >> spotname;
		if (spotname[0] == '0') return;
		for (int i = 1; i <= nodecount; i++) {
			if (strcmp(node[i].name, spotname) == 0) {
				cout << "该景点已经存在，请重新输入！";
				system("pause");
				return;
			}
		}
		cout << "请输入新景点的简介(输入“0”退出)：";
		cin >> spotinfo;
		if (spotinfo[0] == '0') return;
		if (addspot_back(spotname, spotinfo, node, nodecount + 1)) {
			cout << "添加成功！" << endl;
			system("pause");
		}
		else {
			cout << "添加失败！请重新输入！" << endl;
			system("pause");
		}
	}

}